import {baseWsIP} from "@/network/request";

let socket = null
export function initWebSocket(suffix){
    socket = new WebSocket(baseWsIP(suffix))
    socket.onmessage =(e)=>getWebSocketMessage(e)
    socket.onopen =(e)=>webSocketOpen(e)
    socket.onerror =(e)=>webSocketError(e)
    socket.onclose =(e)=>websocketClose(e)
}
export function getWebSocketMessage(e){
    return e
}
export function webSocketOpen(e){
    console.log('断开websocket连接')
}
export function webSocketError(e){
    console.log('断开websocket连接')
    console.log('重新连接')
    initWebSocket()
}
export function websocketClose(e){
    console.log('websocket 断开')
}
